<script>
import bottomNav from "@/components/bottomNav.vue"
import { reactive, toRefs } from 'vue';
import { getData, getData2,getmode } from "../assets/api/home"
import { useRouter } from 'vue-router';
import { ref } from 'vue';
export default {
    components: { bottomNav },
    setup() {



        let router = useRouter();
        let teacherhead=ref([])
        let banner = reactive({
            // 轮播图
            bannerList: null,
            // 轮播图下面的tab
            menuList: null,
            // tab下面的动图
            tabImg: null,
            // 精选课程
            hotClass: [],
            hotClass2: null,
            index: 0,
            hotdata: []
        });
        let getDataFun = () => {
            getData().then((data) => {
                // 轮播图
                banner.bannerList = data.data.results.body.sybnList
                // 轮播图下面的tab
                banner.menuList = data.data.results.body.menuList
                // 精选课程
                // banner.hotClass = data.data.results.body.netList
                banner.hotdata = banner.hotClass.slice(0, 6)
                // tab下面的动图log
                banner.tabImg = data.data.results.body.syzwList
                // console.log(data,1111);
                
                // banner.hotClass.forEach(item=>{
                //    let someteacher= item.teacherImg.split(",")
                //     teacherhead.value.push(someteacher)
                //     console.log(teacherhead.value);
                // })


            })
            getData2().then(res => {
                banner.hotClass2 = res.data.results.list
                // console.log(res.data.results.list);
            })

            getmode("", "1").then(res => {
                // console.log(res);
                banner.hotClass = res.data.results.list
                // ac.dataList = res.data.results.list
                // console.log(ac.dataList);
            })


          
        }

        getDataFun()


        let navigate = (id) => {
            // console.log(id);
            router.push({
                path: "/netshop",
                query: {
                    key: id
                }
            })
            // console.log(router);

        }

        //教师头像
        let tomakehead=()=>{
            // banner.hotClass.forEach(item=>{
            //     console.log(item.teacherImg,22222222);
            // })
        }
        tomakehead()

        // 下拉刷新
        const loading = ref(false);
        const finished = ref(false);
        const onLoad = () => {
            setTimeout(() => {
                for (let i = 0; i < 2; i++) {
                    banner.index += 2
                    banner.hotdata = banner.hotClass.slice(0, banner.index)
                }
                loading.value = false;

                if (banner.hotdata.length >= 17) {
                    finished.value = true;
                }
            }, 1000);
        };

        let goclass = (title) => {
            router.push({
                path: "/classlesson",
                query: {
                    "title": title
                }
            })
        }


        return {
            // 展开banner的内容
            ...toRefs(banner),
            navigate,
            onLoad,
            loading,
            finished,
            goclass,
            teacherhead
        }
    },
}
</script>

<template>
    <div class="container">
        <header>
            <h1>星火英语</h1>
        </header>
        <!-- 广告图片 -->
        <div class="main">
            <div class="box">
                <van-swipe class="my-swipe" :autoplay="2000" indicator-color="white">
                    <van-swipe-item v-for="(item, index) in bannerList" :key="index">
                        <img :src="item.img" alt="" />
                    </van-swipe-item>
                </van-swipe>
            </div>
        </div>
        <!-- 四个选择 -->
        <div class="choose">
            <a @click="goclass(item.name)" class="pic" v-for="(item) in menuList" :key="item">
                <img :src="item.imgUrl" alt="" />
                <h5>{{ item.name }}</h5>
            </a>
        </div>

        <div class="img" v-for="item in tabImg" :key="item">
            <img :src="item.img" alt="">
        </div>


        <!-- 精选课程 -->
        <div class="title">
            <h3>精选课程</h3>
        </div>

        <div class="bodys">
            <van-list v-model:loading="loading" :finished="finished" finished-text="没有啦" @load="onLoad">
                <div @click="navigate(item.key)" class="box-course" v-for="(item, index) in hotdata" :key="index">
                    <div class="course">
                        <div class="titles">
                            <i><img :src="item.sellingPointImg" alt=""></i>
                            <h6 :style="{ color: item.sellingPointColor }">{{ item.sellingPoint }}<span></span></h6>
                        </div>

                        <div class="center">
                            <img :src="item.img" alt="" />

                            <span>{{ item.netSubjectName }}<i></i></span>

                            <div class="text">
                                <h4>{{ item.title }}</h4>
                                <h6>{{ item.liveTime }} | {{ item.period }}课时</h6>

                                <div class="teachermessage">
                                    <!-- <img :src="item.teacherImg" alt=""> -->
                                    <h5>{{ item.teacher }}</h5>
                                </div>
                                
                            </div>
                        </div>


                        <div class="footer">
                            <h6>已购{{ item.buyers }}</h6>
                            <span></span>
                            <h6 class="text2" v-if="item.limitBuyers">限购{{ item.limitBuyers }}</h6>
                            <h5 v-if="item.price"><span>¥{{ item.price }}</span>¥{{ item.disprice }}</h5>
                            <h5 v-if="!item.price">免费</h5>
                        </div>
                    </div>
                </div>
            </van-list>
        </div>




        <bottomNav></bottomNav>

    </div>
</template>


<style lang="scss" scoped>
@import "../assets/css/base.css";

header {
    position: sticky;
    height: 44px;
    background-color: #ffffff;
    top: 0;
    z-index: 2;
    display: flex;
    justify-content: center;

    h1 {
        height: 44px;
        line-height: 44px;
        font-size: 17px;
        font-weight: bolder;
    }
}

.main {
    padding: 0 14px;
    border-radius: 14px;
}

.my-swipe {
    // height: 160px;
    border-radius: 14px;

    .van-swipe-item {
        color: #fff;
        font-size: 20px;
        line-height: 150px;
        text-align: center;
        //   background-color: #39a9ed;
    }
}

/* 四个选择 */
.choose {
    display: flex;
    padding: 20px 14px;
    justify-content: space-between;

    .pic {
        width: 20%;
        display: flex;
        flex-direction: column;
        align-items: center;

        img {
            width: 80%;
            // height: 47px;
            //q
        }

        h5 {
            font-size: 12px;
            height: 40px;
            line-height: 40px;
        }
    }
}

.img {
    padding: 0 14px;
}

.bodys {
    padding-bottom: 60px;
}

.title {
    display: flex;

    h3 {
        font-weight: bold;
        margin-left: 15px;
        height: 66px;
        line-height: 66px;
    }
}

/* 课程信息 */
.course {
    margin: 0px 15px 15px 15px;
    box-shadow: 0px 3px 8px #c4c4c4;
    border-radius: 8px;
    display: flex;
    flex-direction: column;

    .titles {
        margin-top: 7px;
        margin-left: 5px;
        height: 32px;
        display: flex;
        align-items: center;
        background-image: linear-gradient(to right, #f9f9f9, #fff);
        border-radius: 10px;

        i {
            // background-image: url(../assets/img/base3/tongyong-icon.png);
            background-size: 22px 22px;
            width: 22px;
            height: 22px;
            margin: 0px 11px;
        }

        &>h6 {
            display: flex;
            height: 32px;
            align-items: center;
            font-weight: bold;

            span {
                width: 3px;
                height: 3px;
                border-radius: 1px;
                background-color: #211d11;
                align-items: center;
                margin: 0 5px;
            }

            &:last-child {
                span {
                    background-color: transparent;
                }
            }
        }
    }

    .center {
        margin-left: 15px;
        margin-top: 10px;
        display: flex;
        position: relative;

        span {
            position: absolute;
            top: 0px;
            left: 0px;
            display: block;
            width: 92px;
            height: 20px;
            line-height: 20px;
            color: #fffdff;
            font-size: 12px;
            text-align: center;
            font-weight: bold;
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
            border-bottom-right-radius: 10px;
            background-color: #c2c9d9;

            i {
                position: absolute;
                top: 20px;
                left: 0px;
                width: 10px;
                height: 10px;
                background-size: 10px 10px;
                // background-image: url(../assets/img/base3/下载.png);
            }
        }

        >img {
            width: 120px;
            height: 90px;
            border-radius: 10px;
        }

        .text {
            display: flex;
            flex-direction: column;
            margin: 0 15px 0 15px;

            h4 {
                font-weight: bolder;
            }

            h6 {
                color: #c3c3c5;
                height: 30px;
                line-height: 30px;
            }

            h5 {
                font-size: 12px;
                display: flex;
                align-items: center;
                color: #c3c3c5;

                i {
                    // background-image: url(../assets/img/base3/head.jpg);
                    background-size: 25px 25px;
                    width: 25px;
                    height: 25px;
                    margin-right: 5px;
                }
            }
        }
    }
}

/* 课程标题-开头部分 */
/* 课程信息-中间部分 */
/* 课程信息-下面 */
.footer {
    display: flex;
    justify-content: space-between;
    height: 60px;
    align-items: center;
    margin-left: 15px;

    h6 {
        color: #949597;
    }

    span {
        margin: 0px 8px;
        color: #949597;
        width: 2px;
        height: 10px;
        background-color: #f1f0ee;
    }

    .text2 {
        flex: 1;
    }

    h5 {
        margin-right: 14px;
        font-size: 16px;
        font-weight: bold;
        color: #f84108;

        span {
            font-size: 12px;
            text-decoration: line-through
        }
    }
}
.teachermessage{
    display: flex;
    flex-direction: column;
    >img{
        width: 30px;
        height: 30px;
        border-radius: 50%;
    }
}
</style>



